package com.taomu.app.zongchouhuli.http.utls;

import com.alibaba.fastjson.JSONObject;
import com.taomu.app.zongchouhuli.utils.BaseConst;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

public class CommonResponseData extends AbsResponseBodyObservable{

    public CommonResponseData(Observable<ResponseBody> mResponseBodyObservable) {
        super(mResponseBodyObservable);
    }

    @Override
    protected String getResponseDataString(String responseBody) throws Exception {
        JSONObject jsonObject = JSONObject.parseObject(responseBody);
        int code = jsonObject.getIntValue(BaseConst.BASECODE);
        String msg = jsonObject.getString(BaseConst.BASEMSG);
        String data = jsonObject.getString(BaseConst.BASEDATA);
        if(code != BaseConst.CORRECTCODE){
            throw new ServerErrorException(new ServiceResponseErrorBean(code, msg));
        }
        return data == null?"":data;
    }
}
